package net.zdreamer.geracomium.ui.home;

import java.util.ArrayList;
import java.util.List;

import net.zdreamer.geracomium.adapter.FragmentTabAdapter;
import net.zdreamer.geracomium.adapter.FragmentTabAdapter.OnRgsExtraCheckedChangedListener;
import net.zdreamer.geracomium.ui.GeracomiumIntroFragment;
import net.zdreamer.geracomium.ui.GeracomiumReserveFragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.geracomium.R;

public class GeracomiumDetailsActivity extends FragmentActivity implements 
OnClickListener, OnRgsExtraCheckedChangedListener {
	private RadioGroup radio_group;
	private TextView title;
	public List<Fragment> fragments = new ArrayList<Fragment>();
	private ImageView imageView;//滑动条
	private Animation animation;
	private ImageView  title_left;
	LayoutParams layoutParams;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_geracomium_details);
		initViews();
		
	}
	
	private void initViews() {
		
		title_left = (ImageView) findViewById(R.id.back);
		title_left.setOnClickListener(this); 
		
		fragments.add(new GeracomiumIntroFragment());
		fragments.add(new GeracomiumReserveFragment());
		
		radio_group = (RadioGroup) findViewById(R.id.title_details);
		imageView = (ImageView) findViewById(R.id.imageview_toolbar); 
		title = (TextView) findViewById(R.id.title_content);
		title.setText("松龄苑老年养护中心");
		
		FragmentTabAdapter tabAdapter = new FragmentTabAdapter(this, fragments,
				R.id.detail_fragment_layout, radio_group,true);
		tabAdapter.setOnRgsExtraCheckedChangedListener(this);

	}



	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		
		case R.id.back:
			GeracomiumDetailsActivity.this.finish();
			break;
		default:
			break;
		}
		
	}

	@Override
	public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId,
			int index) {
		switch (checkedId) {
		case R.id.radio_info:
			animation = (Animation) AnimationUtils.loadAnimation(GeracomiumDetailsActivity.this, R.anim.translate_left); 
			imageView.startAnimation(animation);
			layoutParams = (LayoutParams) imageView.getLayoutParams();
			layoutParams.gravity = Gravity.LEFT;
			imageView.setLayoutParams(layoutParams);
			break;
		case R.id.radio_reserve:
			animation = (Animation) AnimationUtils.loadAnimation(GeracomiumDetailsActivity.this, R.anim.translate_right); 
			imageView.startAnimation(animation);
			layoutParams = (LayoutParams) imageView.getLayoutParams();
			layoutParams.gravity = Gravity.RIGHT;
			imageView.setLayoutParams(layoutParams);
			break;
		default:
			break;
		}
	}		
}
